<admintpl file="header" />
<style>
	.refund_reason {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		max-width: 100px;
	}
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="{$index != 1 ? 'active' : ''}"><a href="{:U('Order/Adminorder/lists')}">订单列表</a></li>
			<li class="{$index == 1 ? 'active' : ''}"><a href="{:U('Order/Adminorder/lists', ['refund_status' => 1, 'index' => 1])}">退款订单</a></li>
		</ul>
		<form class="well form-search" method="post" action="{:U('Order/Adminorder/lists')}">
			订单状态：
			<select name="status">
				<option value="0">请选择订单状态</option>
				<volist name="order_status" id="vo">
					<option value="{$key}" {$status == $key ? 'selected' : ''}>{$vo}</option>
				</volist>
			</select>

			退款状态：
			<select name="refund_status">
				<option value="0">请选择退款状态</option>
				<volist name="refund_lists" id="vo">
					<option value="{$key}" {$refund_status == $key ? 'selected' : ''}>{$vo}</option>
				</volist>
			</select>

			时间：
			<input type="date" name="start_time" value="{$start_time|default=''}"> ~
			<input type="date" name="end_time" value="{$end_time|default=''}">

			<input type="submit" class="btn btn-primary" value="搜索" />
			<a class="btn btn-danger" href="{:U('Order/Adminorder/lists')}">清空</a>
		</form>

		<form class="js-ajax-form" action="" method="post">
			<table class="table table-hover table-bordered table-list">
				<thead>
					<tr>
						<th width="50">ID</th>
						<th width="150">用户名</th>
                        <th width="50">头像</th>
						<th width="100">订单类型</th>
						<th width="100">数量</th>
						<th width="100">总价格</th>
						<th width="100">付款状态</th>
						<th width="100">退款状态</th>
						<th width="200">退款原因</th>
						<th width="100">下单时间</th>
						<th width="70">操作</th>
					</tr>
				</thead>
				<foreach name="lists" item="vo">
				<tr>
                    <td>{$vo.id}</td>
					<td>{$vo.user_nicename}</td>
					<td><img style="width: 35px;height: 35px;border-radius: 50%;border: transparent;" src="{:sp_get_user_avatar_url($vo['avatar'])}?t={:time()}"></td>
					<td>
						<php>
							if ($vo['type'] == 1) {
								$order_type = '活动';
							} elseif ($vo['type'] == 2) {
								$order_type = '问答';
							} elseif ($vo['type'] == 3) {
								$order_type = '课程';
							}
						</php>
						{$order_type}
					</td>
					<td>{$vo.goods_num}</td>
					<td>
						<php>
							echo floatval($vo['total_money'] / $vo['goods_num'] / 100);
						</php>
					</td>
					<td>{$order_status[$vo['status']]}</td>
					<td>
						<php>
							if ($vo['refund_status'] == 0) {
							$refund_status = '正常';
							} elseif ($vo['refund_status'] == 1) {
							$refund_status = '申请中';
							} elseif ($vo['refund_status'] == 2) {
							$refund_status = '已退款';
							} else {
							$refund_status = '退款失败';
							}
						</php>
						{$refund_status}
					</td>
					<td class="refund_reason">{$vo.refund_reason}</td>
					<td>{:date('Y-m-d H:i:s', $vo['created_at'])}</td>
					<td>
						<if condition="$vo['refund_status'] == 1">
							<a data-href="{:U('Order/Adminorder/do_refund', array('id' => $vo['id']))}"  class="confirm_refund">确认退款</a> |
							<a data-href="{:U('Order/Adminorder/do_refund', array('id' => $vo['id'], 'refuse' => 1))}" class="confirm_refund">拒绝</a>
						</if>
					</td>
				</tr>
				</foreach>
			</table>
			<div class="pagination">{$page}</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/layer/layer_1.js"></script>
	<script>
		$(document).ready(function () {
			$('.confirm_refund').click(function () {
			    var url = $(this).attr('data-href');
                layer.confirm('确定操作吗？', {
                    btn: ['确定', '取消']
                }, function (index) {
                    $.get(url, {}, function (re) {
                        layer.msg(re.info);
						if (re.status) {
						    setTimeout(function () {
								window.location.reload();
                            }, 2000);
						}
                    })
                    layer.close(index);
                });
            });
			
			$('.refund_reason').click(function () {
			    var refund_reason = $(this).text();
			    if (refund_reason != '') {
                    var div = '<div style="margin: 15px;border: 1px solid #cdcdcd;padding: 15px;">' + refund_reason + '</div>'
                    layer.open({
                        type: 1,
                        title: false,
                        closeBtn: 0,
                        btn: ['完成', '取消'],
                        shadeClose: false,
                        content: div,
                    });
				}
            });
        })
	</script>
</body>
</html>